<?php

if (!defined('IN_XLP')) {
	exit('Access Denied!');
}

/**
 * Description of OrderModel
 *
 * @author skyinter
 */
class goodsCategoryModel extends Model {
	
	function __construct() {
		parent::__construct();
		$this->dbTable = 'goods_category';
		$this->page = 20;
	}

	public function add($data) {
		$result = $this->insert($data);
		return $result;
	}

	public function get_list($field='*') {
		return $this->get_tree($field);
	}

	private function get_tree($field='*') {
		$where = " `is_del`=0 ";
		$data  = $this->field($field)->where($where)->order('`id`')->findAll();

		$arr = array();
		foreach ($data as $v) {
			$arr[$v['id']] = $v;
		}
		return $arr;
	}

	public function get_option($selected='') {
		$list   = $this->get_tree();
		$tree   = D('tree')->genTree($list);
		$option = D('tree')->genSelectOption($tree, $selected);

		return $option;
	}

	public function modify($id, $data) {
		$result = $this->update($data, array('id'=>$id));
		return $result;
	}
}